package io.geely.push.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.geely.push.common.utils.PageUtils;
import io.geely.push.common.utils.R;
import io.geely.push.common.validator.ValidatorUtils;
import io.geely.push.modules.sys.entity.ApnUserEntity;
import io.geely.push.modules.sys.service.ApnUserService;

/**
 * 
 *
 * @author qianjiang
 * @email qianjiang@geely.com
 * @date 2018-11-26 16:42:02
 */
@RestController
@RequestMapping("sys/apnuser")
public class ApnUserController {
    @Autowired
    private ApnUserService apnUserService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:apnuser:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = apnUserService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:apnuser:info")
    public R info(@PathVariable("id") Long id){
        ApnUserEntity apnUser = apnUserService.selectById(id);

        return R.ok().put("apnUser", apnUser);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:apnuser:save")
    public R save(@RequestBody ApnUserEntity apnUser){
        apnUserService.insert(apnUser);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:apnuser:update")
    public R update(@RequestBody ApnUserEntity apnUser){
        ValidatorUtils.validateEntity(apnUser);
        apnUserService.updateAllColumnById(apnUser);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:apnuser:delete")
    public R delete(@RequestBody Long[] ids){
        apnUserService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
